﻿<MyBase:CreateTableSchemaBaseWin x:Class="SSDM.CreateTableSchemaFactory.CreateTableSchema_SSCE"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:BaseControl="clr-namespace:MPL.MyControls;assembly=MPL"
    xmlns:WPFToolKits="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    xmlns:MyBase="clr-namespace:SSDM.CreateTableSchemaFactory"
    xmlns:Rules="clr-namespace:MPL.InvalidRulues;assembly=MPL"
    xmlns:AppCommands="clr-namespace:SSDM.GlobalDefine"
    Title="CreateTableSchema_SSCE" Height="480" Width="800">
    <MyBase:CreateTableSchemaBaseWin.CommandBindings>
        <CommandBinding Command="AppCommands:RoutedUICommands.CreateTableCmd" 
                        CanExecute="CommandBinding_CanExecute" 
                        Executed="CommandBinding_Executed"/>
    </MyBase:CreateTableSchemaBaseWin.CommandBindings>
    <Grid>
        <DockPanel>
        <StackPanel DockPanel.Dock="Top" HorizontalAlignment="Center"  Orientation="Horizontal">
            <TextBlock Text="Table Name" VerticalAlignment="Center"/>
            <TextBox x:Name="txtTableName" Width="180" Margin="10" Height="26"/>
        </StackPanel>
        <BaseControl:CommandBar x:Name="cmdBar" DockPanel.Dock="Bottom"
                                HorizontalAlignment="Center"
                                OkButtonCommand="AppCommands:RoutedUICommands.CreateTableCmd"
                                PressCancelButton="cmdBar_PressCancelButton"
                                />
            <DataGrid MinHeight="50"
                     x:Name="myGrid" 
                     ItemsSource="{Binding}"
                     Margin="10"
                     CanUserResizeColumns="False"
                     AutoGenerateColumns="False"       
                     CanUserAddRows="True"
                     CanUserDeleteRows="True"
                     Background="Transparent"
                     GridLinesVisibility="All"
                     RowHeaderWidth="10"                     
                     SelectionMode="Extended"
                     SelectionUnit="FullRow"
                     HeadersVisibility="All"
                     RowBackground="White" 
                     AlternatingRowBackground="AliceBlue"
                     AlternationCount="2" 
                     >
                <DataGrid.Columns>
                    <DataGridTextColumn Width="110" Header="Column Name">
                        <DataGridTextColumn.Binding>
                            <Binding Path="ColumnName" Mode="TwoWay" ValidatesOnDataErrors="True" 
                                     ValidatesOnExceptions="True" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <Rules:LengthValidationRule MaxLenght="20" IsCheckEmpty="True" DisplayErrorPropertyName="Column Name"/>
                                </Binding.ValidationRules>
                            </Binding>
                        </DataGridTextColumn.Binding>
                    </DataGridTextColumn>
                    <DataGridComboBoxColumn
                            x:Name="columnTypeColumn"
                            TextBinding="{Binding Path=ColumnType, Mode=TwoWay}"
                            Width="100" Header="Column Type">
                    </DataGridComboBoxColumn>
                    <DataGridTemplateColumn Width="120" Header="Length">
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <BaseControl:MaskTextBox X_MaskType="Digits" X_MaxValue="4000"  
                                                         Text="{Binding ColumnLength,Mode=TwoWay}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ColumnLength}" HorizontalAlignment="Center" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridCheckBoxColumn
                            x:Name="allowNullsColumn"
                    Binding="{Binding Path=AllowNulls, Mode=TwoWay}"
                            Width="100" Header="Allow Nulls"/>
                    <DataGridCheckBoxColumn
                            x:Name="isUniqueColumn"
                    Binding="{Binding Path=IsUnique, Mode=TwoWay}"
                            Width="100" Header="Unique"/>
                    <DataGridCheckBoxColumn
                            x:Name="isPKColumn"
                            Binding="{Binding Path=IsPK, Mode=TwoWay}"
                            Width="100" Header="Primary Key"/>
                </DataGrid.Columns>
            </DataGrid>
        </DockPanel>
    </Grid>
</MyBase:CreateTableSchemaBaseWin>
